<?php

/**
 * This is the model class for table "tbl_shipping_options".
 *
 * The followings are the available columns in table 'tbl_shipping_options':
 * @property integer $id
 * @property string $description
 * @property string $accountno
 * @property integer $inactive
 * @property integer $sort
 */
class ShippingOptions extends CActiveRecord
{
    /**
     * Returns the static model of the specified AR class.
     * @return ShippingOptions the static model class
     */
    public static function model($className = __CLASS__)
    {
        return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName()
    {
        return 'tbl_shipping_options';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules()
    {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('inactive, sort', 'numerical', 'integerOnly' => true),
            array('description', 'length', 'max' => 36),
            // The following rule is used by search().
            // Please remove those attributes that should not be searched.
            array('id, description, inactive, sort', 'safe', 'on' => 'search'),
        );
    }

    /**
     * @return array relational rules.
     */
    public function relations()
    {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
        );
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels()
    {
        return array(
            'id' => 'ID',
            'description' => 'Description',
            'inactive' => 'Inactive',
            'sort' => 'Sort',
        );
    }

    /**
     * Retrieves a list of models.
     * @return array of the models .
     */
    public function getList()
    {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria = new CDbCriteria();
        $criteria->addColumnCondition(array('inactive'=>0));
        $criteria->order = 'sort ASC';
        $shippingList  = $this->findAll($criteria);
        $data = array();
        foreach($shippingList as $item){
            $data[$item->id] = "$item->description - $item->accountno";
        }
        return $data;
    }
}